//
//  JsBarButtonItem.m
//  MpaClientIos
//
//  Created by Gikki Ares on 2023/4/21.
//  Copyright © 2023 Yach. All rights reserved.
//

#import "JsBarButtonItem.h"
#import "JsViewHIli.h"
#import "JsColorManager.h"
#import "JsBundleManager.h"
#import "JsImageView.h"
@implementation JsBarButtonItem

//size用多大尺寸?
- (instancetype)initWithImage:(UIImage *)image target:(id)target action:(SEL)action {
	return [self initWithImage:image size:CGSizeMake(20,20) target:target action:action];
}

- (instancetype)initWithImage:(UIImage *)image size:(CGSize)size target:(id)target action:(SEL)action {
	
	JsImageViewVm * vm = [JsImageViewVm new];
	vm.image = image;
	vm.imageSize = size;
	JsImageView * iv = [[JsImageView alloc] initWithVm:vm];
	iv.translatesAutoresizingMaskIntoConstraints = NO;
	[iv.widthAnchor constraintEqualToConstant:40].active = YES;
	[iv.heightAnchor constraintEqualToConstant:40].active = YES;
	[iv addTapTarget:target selector:action];
	
	if(self = [super initWithCustomView:iv]) {
		
	}
	return self;
}

/**
 1,系统导航栏颜色 007aff
 
 */
+ (UIBarButtonItem *)standardBackBarButtonItemWithTitle:(NSString *)title target:(id)target action:(SEL)action {
	
	JsViewHIliVm * vm = [[JsViewHIliVm alloc]init];
	vm.leftImage = [JsBundleManager iconInBundleNamed:@"left_007aff.png"];
	vm.title = @"返回";
	vm.leftImageSize = CGSizeMake(18, 22);
	vm.leftImageLeading = 0;
	vm.titleLeading = 5;
	vm.padding = UIEdgeInsetsMake(2,0,-2,-10);
	vm.titleColor = [UIColor colorWithHex:0x007aff];
		//	vm.backgroundColor = [UIColor greenColor];
		//	vm.contentBackgroundColor = [UIColor redColor];
	JsViewHIli* view = [[JsViewHIli alloc]initWithVm:vm];
	view.tag = 100;
	view.isClickable = YES;
	[view.widthAnchor constraintEqualToConstant:100].active = YES;
	[view.heightAnchor constraintEqualToConstant:30].active = YES;
	[view addTapTarget:target selector:action];
	UIBarButtonItem * bbiBack = [[UIBarButtonItem alloc]initWithCustomView:view];
	return bbiBack;
}

@end
